package com.uton.rfidcontroller.viewmodel.base;

import android.databinding.ObservableBoolean;

import com.uton.rfidcontroller.common.interfaces.INetController;
import com.uton.rfidcontroller.common.net.base.BaseObserver;

import io.reactivex.Observable;
import io.reactivex.ObservableTransformer;

/**
 * Created by 王家宝 on 2017/8/30.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public abstract class BaseViewModel {

    public final ObservableBoolean showLoading = new ObservableBoolean(true);

    public final ObservableBoolean showData = new ObservableBoolean(false);

    public <T> void go(Observable iObservable, final INetController<T> netController) {
        iObservable
                .compose(setObservable())
                .subscribe(new BaseObserver<T>() {
                    @Override
                    protected void onHandleSuccess(T t) {
                        netController.onSuccess(t);
                    }

                    @Override
                    protected void onHandleError() {
                        netController.onError();
                    }

                    @Override
                    protected void onHandleComplete() {
                        netController.onComplete();
                    }
                });
    }

    //统一数据刷新方法
    public abstract void refreshData();

    //返回指定Observable
    public abstract ObservableTransformer setObservable();

    //加载更多时需要重写该方法
    public void doOnLoadMore() {
    }

}
